<?php

namespace plugins\rwechat\lib;

use EasyWeChat\Factory;

class Wechat
{
    static $config = [
        'app_id' => '',
        'secret' => '',
        'token' => '',

        // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
        'response_type' => 'array',

        'oauth' => [
            'scopes'   => ['snsapi_userinfo'],
            'callback' => '/wechat/auth/oauth_back',
        ],

        // 'notify_url' => '',
    ];

    static $app = null;

    static $payment = null;

    public static function app()
    {
        if (self::$app == null) {
            $config = [
                'app_id' => cmf_get_option('rwechat')['appid'],
                'secret' => cmf_get_option('rwechat')['secret'],
                'token' => cmf_get_option('rwechat')['token'],
            ];
            self::$app = Factory::officialAccount($config);
        }
        return self::$app;
    }

    public static function payment()
    {
        if (self::$payment == null) {
            self::$payment = Factory::payment(self::$config);
        }
        return self::$payment;
    }
}
